package br.com.materiais.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import br.com.materiais.dao.MateriaisDao;
import br.com.materiais.model.MaterialModel;

public class MateriaisForm extends ActionForm
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 7158834097230823650L;
    private MaterialModel material = new MaterialModel();
 	
	public MaterialModel getMateriais()
	{
		return this.material;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) 
	{
		ActionErrors errors = new ActionErrors();
		
		if(new MateriaisDao().isCodigoMaterialExiste(material))
			errors.add("duplicidade",new ActionMessage("erro.material.duplicidade"));
		    
		return errors;

		
	}

}
